﻿using System;

namespace FscNET.Apm
{
    /// <summary>
    /// Indicates that a deadlock would occur because a the UI thread is waiting for an AsyncEnumerator 
    /// to complete running but it can't since the UI thread is blocked.
    /// </summary>
#if !SILVERLIGHT
    [Serializable]
#endif
    public sealed class FrozenUIExceptionArgs : ExceptionArgs
    {
#if !SILVERLIGHT
        [NonSerialized]
#endif
        private readonly AsyncEnumerator m_ae;
        internal FrozenUIExceptionArgs(AsyncEnumerator ae)
        {
            m_ae = ae;
        }

        /// <summary>
        /// Returns a reference to the AsyncEnumerator that the UI thread is waiting for.
        /// </summary>
        public AsyncEnumerator AsyncEnumerator { get { return m_ae; } }

        /// <summary>Gets a message that describes the current exception.</summary>
        public override string Message
        {
            get
            {
                //Contract.Assume(m_ae != null);
                return "AsyncEnumerator debug information:\r\n" + m_ae.ToString();
            }
        }
    }


}
